package com.corp.controller;

import com.corp.entity.Customer;
import com.corp.platform.common.response.RespResult;
import com.corp.service.ICustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yf
 * @email 68070787@qq.com
 * @date 2020/6/22
 */
@RestController
@RefreshScope
public class DemoOneController {

    @Autowired
    private ICustomerService customerService;

    @Value("${user.name}")
    String userName;

    @Value("${user.age:25}")
    int age;

    @RequestMapping("/user")
    public String simple() {
        String s = "Hello Nacos Config!" + "Hello " + userName + " " + age + "!";
        return s;
    }

    @RequestMapping("customer/add")
    public Boolean addCustomer() {
        Customer customer = new Customer().setAge(18).setName("这三个是否");
        boolean rel = customerService.add(customer);

        return rel;
    }

    @GetMapping("customer/one")
    public RespResult<Customer> one() {
        System.out.println(Thread.currentThread().getName());
        Customer customer = customerService.getOne(1l);
        return RespResult.data(customer);
    }
}
